<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0px;
            margin: 0px;
        }
        .wrap {
            width: 400px;
            /* height: 400px; */
            background: skyblue;
        }
        .box1{
            margin-top: 50px;
            width: 100px;
            height: 100px;
            background: rgb(230, 71, 79);
            float: left;
        }
        .box2{
            width: 100px;
            height: 100px;
            background: rgb(71, 230, 127);
            float: left;
        }
        .clearfix:before, 
        .clearfix:after{
            display: table;
            content: '';
            clear: both;
        } 
    </style>
</head>
<body>
    <h1>解决高度塌陷和外边距重叠问题</h1>
    <hr>
    <!-- 给父容器设置clearfix即可解决父容器高度塌陷和外边距重叠问题 -->
    <div class="wrap clearfix">
       <div class="box1"></div>
       <div class="box2"></div>
    </div>
    <!--在很多大公司中推荐使用 .clearfix的伪类来解决此类问题-->
</body>
</html>